package com.example.order.service.impl;

import com.example.order.config.ServiceResponse;
import com.example.order.mapper.OrderComplainMapper;
import com.example.order.service.IOrderComplaint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.OrderComplain;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class OrderComplaintImpl implements IOrderComplaint {

    @Autowired
    private OrderComplainMapper orderComplainMapper;

    @Override
    public ServiceResponse orderComplaint(OrderComplain orderComplain) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        orderComplain.setComplainTime(dateFormat.format(new Date()));
        orderComplain.setComplainstatus("未受理");
        Integer complainByOrderNumber = orderComplainMapper.getComplainByOrderNumber(orderComplain.getOrderNumber());
        if (complainByOrderNumber>0){
            //如果该订单已投诉，则不能进行再次投诉
            return ServiceResponse.createError();
        }
        int i = orderComplainMapper.insertSelective(orderComplain);
        if (i>0){
            return ServiceResponse.createSuccess();
        }else{
            return ServiceResponse.createError();
        }
    }
}
